<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-3.1.1.js"></script>
    <script src="js/base.js"></script>
    <script src="js/md5.js"></script>

</head>
<body>
    <input type="text" id="signName"/> <br>
    <input type="password" id="password"/><br>
<button onclick="return onSignInClick();">登陆</button>
    <button onclick="return showToken()">显示token</button>
    <div id="showTokenDiv"></div>
<script>
    function onSignInClick(){
        let signName=document.getElementById("signName").value;
        let password=document.getElementById("password").value;
        if(signName.length<6){
            alert("用户名格式不正确");
            return ;
        }
        if(password.length<6){
            alert("密码格式不正确");
            return ;
        }
        let json={};
        json.signName=signName;
        json.password=md5(password+"qf");
        $.rest("POST","http://localhost:8080/user/signin",json,function(r){
            console.info(r);
            let token=r.result.token;
            localStorage.setItem("token",token);
            sessionStorage.setItem("loginFlag","1");
            window.location.href="http://localhost:8080/index.html";
        });
    }
    function showToken(){
        let token=localStorage.getItem("token");
        document.getElementById("showTokenDiv").innerHTML=token;
    }
</script>
</body>
</html>